package com.coding.controller;

import com.coding.base.pojo.BaseModel;
import com.coding.base.pojo.PageQueryModel;
import com.coding.base.util.DateUtil;
import com.coding.pojo.Comment;
import com.coding.service.CommentService;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @auther wangchenghao
 * @date 2020/9/19
 **/
@Controller
@ResponseBody
@RequestMapping("comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @ApiOperation("新增帖子评论")
    @RequestMapping(value = "/addComment", method = {RequestMethod.PUT})
    public BaseModel addpost(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                             @ApiParam("帖子id") @RequestParam(value = "post_id", required = true) Integer post_id,
                             @ApiParam("评论内容") @RequestParam(value = "comment_name", required = true) String comment_name
    ) throws Exception {
        BaseModel model = new BaseModel();
        Comment comment = new Comment();
        comment.setComment_kind("post");
        comment.setComment_name(comment_name);
        comment.setComment_user_id(user_id);
        comment.setComment_time(DateUtil.getStringDate());
        comment.setSource_id(post_id);
        commentService.addNewPost(comment, model);
        return model;
    }

    @ApiOperation("新增圈子评论")
    @RequestMapping(value = "/addGroupComment", method = {RequestMethod.PUT})
    public BaseModel addGroupPost(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                  @ApiParam("圈子id") @RequestParam(value = "group_id", required = true) Integer group_id,
                                  @ApiParam("评论内容") @RequestParam(value = "comment_name", required = true) String comment_name
    ) throws Exception {
        BaseModel model = new BaseModel();
        Comment comment = new Comment();
        comment.setComment_kind("group");
        comment.setComment_name(comment_name);
        comment.setComment_user_id(user_id);
        comment.setSource_id(group_id);
        comment.setComment_time(DateUtil.getStringDate());

        commentService.addNewPost(comment, model);
        return model;
    }

    @ApiOperation("新增班级评论")
    @RequestMapping(value = "/addClassComment", method = {RequestMethod.PUT})
    public BaseModel addClassPost(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                  @ApiParam("班级id") @RequestParam(value = "class_id", required = true) Integer class_id,
                                  @ApiParam("评论内容") @RequestParam(value = "comment_name", required = true) String comment_name
    ) throws Exception {
        BaseModel model = new BaseModel();
        Comment comment = new Comment();
        comment.setComment_kind("class");
        comment.setComment_name(comment_name);
        comment.setComment_user_id(user_id);
        comment.setSource_id(class_id);
        comment.setComment_time(DateUtil.getStringDate());
        commentService.addNewPost(comment, model);
        return model;
    }

    @ApiOperation("新增主要景点评论")
    @RequestMapping(value = "/addMainPlaceComment", method = {RequestMethod.PUT})
    public BaseModel addMainPlaceComment(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                         @ApiParam("班级id") @RequestParam(value = "mian_place_id", required = true) Integer mian_place_id,
                                         @ApiParam("评论内容") @RequestParam(value = "comment_name", required = true) String comment_name
    ) throws Exception {
        BaseModel model = new BaseModel();
        Comment comment = new Comment();
        comment.setComment_kind("main_place");
        comment.setComment_name(comment_name);
        comment.setComment_user_id(user_id);
        comment.setSource_id(mian_place_id);
        commentService.addNewPost(comment, model);
        return model;
    }

    @ApiOperation("新增景点评论")
    @RequestMapping(value = "/addPlaceComment", method = {RequestMethod.PUT})
    public BaseModel addPlaceComment(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) Integer user_id,
                                     @ApiParam("景点id") @RequestParam(value = "place_id", required = true) Integer place_id,
                                     @ApiParam("评论内容") @RequestParam(value = "comment_name", required = true) String comment_name
    ) throws Exception {
        BaseModel model = new BaseModel();
        Comment comment = new Comment();
        comment.setComment_kind("place");
        comment.setComment_name(comment_name);
        comment.setComment_user_id(user_id);
        comment.setSource_id(place_id);
        comment.setComment_time(DateUtil.getStringDate());
        commentService.addNewPost(comment, model);
        return model;
    }

    @ApiOperation("获得帖子评论")
    @RequestMapping(value = "/getPostComments", method = {RequestMethod.GET})
    public BaseModel getPostComments(@ApiParam("帖子id") @RequestParam(value = "post_id", required = true) Integer post_id,
                                     @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        commentService.getByPostId(post_id, pageQueryModel, model);
        return model;

    }

    @ApiOperation("获得圈子评论")
    @RequestMapping(value = "/getGroupCom", method = {RequestMethod.GET})
    public BaseModel getGroupComments(@ApiParam("圈子id") @RequestParam(value = "group_id", required = true) Integer group_id,
                                      @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        commentService.getByGroupId(group_id, pageQueryModel, model);
        return model;

    }

    @ApiOperation("获得班级评论")
    @RequestMapping(value = "/getClassComments", method = {RequestMethod.GET})
    public BaseModel getClassComments(@ApiParam("班级id") @RequestParam(value = "class_id", required = true) Integer class_id,
                                      @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        commentService.getByClassId(class_id, pageQueryModel, model);
        return model;

    }

    @ApiOperation("获得主要景点评论")
    @RequestMapping(value = "/getMainPlaceComments", method = {RequestMethod.GET})
    public BaseModel getMainPLaceComments(@ApiParam("班级id") @RequestParam(value = "main_place_id", required = true) Integer main_place_id,
                                          @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        commentService.getByMainPlaceId(main_place_id, pageQueryModel, model);
        return model;

    }

    @ApiOperation("获得景点评论")
    @RequestMapping(value = "/getPlaceComments", method = {RequestMethod.GET})
    public BaseModel getPLaceComments(@ApiParam("班级id") @RequestParam(value = "place_id", required = true) Integer place_id,
                                      @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        commentService.getByPlaceId(place_id, pageQueryModel, model);
        return model;

    }

    @ApiOperation("获得圈子最新评论")
    @RequestMapping(value = "/getGroupComments", method = {RequestMethod.GET})
    public BaseModel getPost(@ApiParam("圈子id") @RequestParam(value = "group_id", required = true) Integer group_id,
                             @ModelAttribute PageQueryModel pageQueryModel) throws Exception {
        BaseModel model = new BaseModel();
        commentService.getByPostId(group_id, pageQueryModel, model);
        return model;

    }
}

